﻿using System.Collections.Generic;
using NUnit.Framework;
using OsamesFrameworkCore.Configuration;
using OsamesFrameworkCore.Logging;
using OsamesFrameworkCore.Plugins;
using OsamesFrameworkCore.Tools;

namespace TestOsamesFrameworkCore.Plugins.Tools
{
    [TestFixture]
    public class TestReflectionTools : TestsBase
    {
        [Test]
        public void TestFindPublicConcreteClassImplementingIPlugin()
        {
            List<IPlugin> lstPlugins = ReflectionTools.FindPublicConcreteClassImplementing<IPlugin>(CoreConfiguration.PluginsDirectoryPath);
            Assert.Greater(lstPlugins.Count, 0, "No IPlugin found");
            string strMessage = string.Format("{0} plugins found", lstPlugins.Count);
            LoggerService.LogToOutput(strMessage);
            Log(LogLevel.Info, strMessage);
        }

        [Test]
        public void TestFindPublicConcreteClassImplementingWithPathIPlugin()
        {
            List<KeyValuePair<string,IPlugin>> lstPlugins = ReflectionTools.FindPublicConcreteClassWithPathImplementing<IPlugin>(CoreConfiguration.PluginsDirectoryPath);
            Assert.Greater(lstPlugins.Count, 0, "No IPlugin found");
            string strMessage = string.Format("{0} plugins found", lstPlugins.Count);
            LoggerService.LogToOutput(strMessage);
            Log(LogLevel.Info, strMessage);
            int iCount = lstPlugins.Count;
            for(int i = 0; i < iCount; i++)
            {
                strMessage = string.Format("Plugin type : {0}, path : {1}", lstPlugins[i].Value, lstPlugins[i].Key);
                LoggerService.LogToOutput(strMessage);
                Log(LogLevel.Info, strMessage);
            }
        }
    }
}
